﻿@using RoccaStore.Extensions
@using RoccaStore.Utils
@model RoccaStore.Web.Models.FileViewModel
@{
    ViewBag.Title = "Download " + Model.Slug.Title;
    Layout = "~/Views/Shared/_Layout.cshtml";

    string hashId = string.Empty;

    if (!string.IsNullOrEmpty(Model.HashedData) && !Model.HashedData.Equals(Model.Slug.Key))
    {
        dynamic hashed = HashUtils.DecodeDynamicHash(Model.HashedData, Model.Slug.Key);
        hashId = hashed.ID.ToString();
    }
}
<div class="content">
    <a href="/" class="logo  middle"></a>
    @if (Model.Slug.Deleted.HasValue)
    {
        <h1><b>Download deleted on: </b></h1>
        <div class="box">
            <p><b>File name:</b> @Model.File.Filename</p>
            <p><b>File size:</b> @(Model.File.FormattedSize)</p>
        </div>
    }
    else
    {
        <h1><b>Download:</b> @Model.Slug.Title</h1>
        <div class="box">
            @if (Model.Slug.File != null)
            {        
                <p><b>File name:</b> @Model.File.Filename</p>
                <p><b>File size:</b> @Model.File.FormattedSize</p>
                <a href="http://@Request.Url.Authority/download/@Model.Slug.Name/@Model.HashedData" class="clear download-button">@(Model.Slug.Type == RoccaStore.Enums.SlugType.Group ? "Download collection" : "Download file")</a>
            }
            @foreach (var item in Model.Group)
            {
                string hash = string.Empty;

                if (!string.IsNullOrEmpty(hashId))
                {
                    hash = HashUtils.EncodeDynamicHash(new { ID = Convert.ToInt32(hashId), Action = "Email" }, item.Key);
                }
                else if(item.IsSecure)
                {
                    hash = item.Key;
                }
                
                <div class="multiple-files">
                    <div class="item web-uploadify" id="upload-computer-queue">
                        <div class="details">
                            <span class="fileName">@item.Title</span>
                            <span class="data">- @item.File.Size.FormatBytes()</span>
                            <div class="divider"></div>
                            <a href="http://@Request.Url.Authority/download/@item.Name/@hash" class="clear download-button download-button-small">Download file</a>
                        </div>
                    </div>
                </div>
            }
        </div>
    }
    <!-- /box -->
</div>
<!-- /content -->